package Jan;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Lieferant {
	
	public int lieferant_ID;
	public String lieferant_name;
	public String strasse;
	public String hausnummer;
	public String plz;
	public String ort;
	public String email;
	public String telefon;
	public int filiale;
		

	public Lieferant(int lieferant_ID, String lieferant_name, String strasse,
			String hausnummer, String plz, String ort, String email,
			String telefon, int filiale) {
		this.lieferant_ID = lieferant_ID;
		this.lieferant_name = lieferant_name;
		this.strasse = strasse;
		this.hausnummer = hausnummer;
		this.plz = plz;
		this.ort = ort;
		this.email = email;
		this.telefon = telefon;
		this.filiale = filiale;
	}

		


	public int getLieferant_ID() {
		return lieferant_ID;
	}




	public void setLieferant_ID(int lieferant_ID) {
		this.lieferant_ID = lieferant_ID;
	}




	public String getLieferant_name() {
		return lieferant_name;
	}




	public void setLieferant_name(String lieferant_name) {
		this.lieferant_name = lieferant_name;
	}




	public String getStrasse() {
		return strasse;
	}




	public void setStrasse(String strasse) {
		this.strasse = strasse;
	}




	public String getHausnummer() {
		return hausnummer;
	}




	public void setHausnummer(String hausnummer) {
		this.hausnummer = hausnummer;
	}




	public String getPlz() {
		return plz;
	}




	public void setPlz(String plz) {
		this.plz = plz;
	}




	public String getOrt() {
		return ort;
	}




	public void setOrt(String ort) {
		this.ort = ort;
	}




	public String getEmail() {
		return email;
	}




	public void setEmail(String email) {
		this.email = email;
	}




	public String getTelefon() {
		return telefon;
	}




	public void setTelefon(String telefon) {
		this.telefon = telefon;
	}




	public int getFiliale() {
		return filiale;
	}




	public void setFiliale(int filiale) {
		this.filiale = filiale;
	}




	public static Lieferant transformOfNewSupplier(Customer customer, Connection con_o) {
		Lieferant lieferant = new Lieferant(
				generateNewSupplierIDOnlineShop(con_o), 
				customer.getCustomer_firstname()+" "+customer.getCustomer_lastname(), 
				customer.getCustomer_delivery_street(), 
				customer.getCustomer_deliv_street_number(), 
				customer.getCustomer_delivery_postal_code(), 
				customer.getCustomer_delivery_place(), 
				customer.getCustomer_email(), 
				customer.getCustomer_phone_number(), 
				1);
		return lieferant;
	}
	
	private static int generateNewSupplierIDOnlineShop(Connection con_o) {
		int newCustomerID = 0;
		ResultSet rs1 = null;
		Statement stmt1 = null;
		try {
			stmt1 = con_o.createStatement();
			rs1 = stmt1.executeQuery("SELECT MAX(LIEFERANT_ID) AS LIEFERANT_ID FROM LIEFERANT"); 		
				while (rs1.next()) {
					newCustomerID = rs1.getInt("LIEFERANT_ID") + 1;
				}
				stmt1.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		return newCustomerID;
	}



}
